package com.pro.service.imple;

import com.pro.mapper.CouponMapper;
import com.pro.pojo.JsUserCoupon;
import com.pro.pojo.JsUserCouponUsed;
import com.pro.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author cyj
 * @date 2022.3.17$ 13.59$
 * @content :
 */
@Service
public class CouponServiceImple implements CouponService {
    @Autowired
    private CouponMapper mapper;
    /**
     * @author cyj
     * @date 2022.3.17$ 14.12$
     * @content :获取所有的优惠卷
     */
    @Override
    public List<JsUserCoupon> getAllCoupon(String couponName, String online, String grant, String startDate, String endDate, Integer limit, Integer page) {
        page = (page-1)*limit;
        return mapper.getAllCoupon(couponName,online,grant,startDate,endDate,limit, page);
    }
    /**
     * @author cyj
     * @date 2022.3.17$ 14.13$
     * @content :获取所有的优惠卷
     */
    @Override
    public Integer countCoupon() {
        return mapper.countCoupon();
    }
    /**
     * @author cyj
     * @date 2022.3.17$ 14.44$
     * @content :获取所有的优惠卷
     */
    @Override
    public JsUserCoupon getCouponById(Integer couponId) {
        return mapper.getCouponById(couponId);
    }
    /**
     * @author cyj
     * @date 2022.3.17$ 15.00$
     * @content :删除一个优惠卷
     */
    @Override
    public Boolean delCoupon(Integer id) {
        return mapper.delCoupon(id);
    }
    /**
     * @author cyj
     * @date 2022.3.17$ 15.26$
     * @content :更改一个优惠卷上下限状态
     */
    @Override
    public Boolean updateOnline(Integer couponId,Integer online,Integer updateId,String updateDate) {
        return mapper.updateOnline(couponId,online,updateId,updateDate);
    }
    /**
     * @author cyj
     * @date 2022.3.17$ 16.54$
     * @content :添加一个优惠卷
     */
    @Override
    public Boolean addCoupon(JsUserCoupon coupon) {
        return mapper.addCoupon(coupon);
    }
    /**
     * @author cyj
     * @date 2022.3.18$ 8.34$
     * @content :获取所有的用户优惠卷
     */
    @Override
    public List<JsUserCoupon> getUserCoupons(String account, String nickname, Integer limit, Integer page) {
        page = (page-1)*limit;
        return mapper.getUserCoupons(account,nickname,limit, page);
    }
    /**
     * @author cyj
     * @date 2022.3.18$ 8.40$
     * @content :用户优惠卷计数
     */
    @Override
    public Integer userCouponCount(String account, String nickname) {
        return mapper.userCouponCount(account,nickname);
    }
    /**
     * @author cyj
     * @date 2022.3.18$ 8.54$
     * @content :添加优惠卷
     */
    @Override
    public Boolean giveCoupon(List<JsUserCouponUsed> jsUserCouponUsed) {
        Boolean flag = true;
        for(Integer i = 0;i<jsUserCouponUsed.size();i++){
            Boolean inFlag = mapper.giveCoupon(jsUserCouponUsed.get(i));
            if(!inFlag){
                flag = false;
            }
        }
        return flag;
    }

}
